<#assign module="sys"/>

<@override name="header">
</@override>
<@override name="body">
<div class="row">
  <div class="col-xs-10">
  	<form class="form-inline" role="form">
  		<div class="form-group">
		    <input type="text" class="form-control" name="name" value="${name?if_exists}" placeholder="角色名称">
	  	</div>
	  	<button type="submit" class="btn btn-primary"><i class="icon-search"></i>&nbsp;搜索</button>
  	</form>
  </div>
  <div class="col-xs-2">
  	<button class="pull-right btn btn-primary" onclick="window.location='${ctx}/role/add';"><i class="icon-plus"></i>&nbsp;添加新角色</button>
  </div>
</div>
<div class="row margin-top">
	<div class="col-xs-12">
	<div class="panel panel-primary">
	<div class="table-responsive">
		<table class="table table-hover table-striped">
			<thead>
			<tr style="font-size:14px;">
				<th>名称</th>
				<th>描述</th>
				<@shiro.isMainCompany>
					<th>所属公司</th>
				</@shiro.isMainCompany>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
				<#if (page.content)?? >
			  	<#list page.content as data>
					<tr>
						<td>${data.name?if_exists}</td>
						<td>${data.desc?if_exists}</td>
						<#if mainCompany==true>
							<td>${data.companyName?if_exists}</td>
						</#if>
						<td>
							<a href="${ctx}/role/edit/${data.id}" class="btn-link">编辑</a>
							<#if !data.isInternal>
							<a href="javascript:;" data-value="${data.id}" class="btn-link deletethis">删除</a>
							</#if>
						</td>
					</tr>
				</#list>
				</#if>
			</tbody>
		</table>
		<#if page.totalElements??>
		<ul class="pagination pull-right pagination-sm">
			<li><a>共 ${page.totalElements} 条数据</a></li>
			<@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/role/list">
				<@pg.param name="name" value="${name?if_exists}"/>
				<@pg.index>
					<@pg.first>
						<li><a href="${pageUrl}">&laquo;</a></li>
					</@pg.first>
					<@pg.prev>
						<li><a href="${pageUrl}">&lsaquo;</a></li>
					</@pg.prev>
					<@pg.pages>
						<#if  currentPageNumber == pageNumber >
							<li class="active"><a href="#">${pageNumber}</a></li>
						<#else>
							<li><a href="${pageUrl}">${pageNumber}</a></li>
						</#if>
					</@pg.pages>
					<@pg.next>
						<li><a href="${pageUrl}">&rsaquo;</a></li>
					</@pg.next>
					<@pg.last>
						<li><a href="${pageUrl}">&raquo;</a></li>
					</@pg.last>
				</@pg.index>
			</@pg.pager>
		</ul>
		</#if>
	</div>
	</div>
	</div>
</div>
</@override>
<@override name="footer">
<script type="text/javascript">
	var thisButton;
	function deleteRole() {
	    $.post('${ctx}/role/delete',{'id':thisButton.attr("data-value")},function(data){
	            if(data.success){
	            	thisButton.parent().parent().remove();
	                $.scojs_message('角色删除成功', $.scojs_message.TYPE_OK);
	            } else {
	                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
	            }
	    },'json');
	}
	$(document).ready(function(){
	    $(".deletethis").click(function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "你真的要删除该角色吗？",
	            action:deleteRole
	          });
	          confirm.show();
	    });
	});
</script>
</@override>
<@extends name="../layout.ftl"/>